<template>
  <div>
      <el-menu :default-active="this.$route.path" class="el-menu-demo" mode="horizontal"  router >
        <!--<el-menu-item index="1">
        </el-menu-item>-->
        <el-menu-item>
            <el-image :src="require('../../img/littleIcon/doctorLogo.png')"></el-image>
        </el-menu-item>
        <el-menu-item style="padding-right:300px;padding-left:30px">
            <el-input placeholder="医生姓名"></el-input>&nbsp;
            <el-button type="primary" icon="el-icon-search" size="mini">搜索</el-button>
        </el-menu-item>
        <el-menu-item index="/">
          <el-image style="width:30px;padding-top:12px;padding-left:170px" :src="require('../../img/littleIcon/home.png')"></el-image>
          <label style="padding-top:10px">     返回首页</label>
        </el-menu-item>
        <el-menu-item style="padding-left:200px" @click="login" v-if="loginFlag">
            <div>
                <span>登录</span>
            </div>
        </el-menu-item>
        <el-menu-item style="padding-left:200px" @click="outLogin" v-if="!loginFlag">
            <div>
                <span><label style="font-size:20px;color:blue;">{{this.$store.state.loginUser.name}}</label>&nbsp;&nbsp;&nbsp;&nbsp;退出</span>
            </div>
        </el-menu-item>
       
        <el-submenu index="5"   class="menuItem">
            <template slot="title">我</template>
            <div>
              <el-menu-item index="2-1" >设置</el-menu-item>
              <el-menu-item index="2-2" >选项2</el-menu-item>
              <el-menu-item index="2-3" >选项3</el-menu-item>
            </div>
            
        </el-submenu>
    </el-menu>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  data() {
    return {
      loginFlag:this.$store.state.loginFlag
    }
  },
  methods:{
    login(){
      this.$router.push("/login")
      this.$store.commit('loginFlagInit',false)
    },
    outLogin(){
      axios.get("/member/sessionFlag")
      .then(res => {
        this.$store.commit('loginFlagInit',res.data)
        this.loginFlag=res.data
        this.$store.commit("loginUserInit",'')
      })
      .catch(err => {
        console.error(err); 
      })
    }
  },
  created(){
    if(this.$store.state.loginUser!=''){
      this.$store.commit('loginFlagInit',false)
    }else{
      this.$store.commit('loginFlagInit',true)
    }
  }
}
</script>

<style>

</style>